from abc import ABC, abstractmethod

# 产品类
class Product:
    def __init__(self):
        self.parts = []
    
    def add(self, part):
        self.parts.append(part)
    
    def show(self):
        return f"产品包含: {', '.join(self.parts)}"

# 抽象建造者
class Builder(ABC):
    @abstractmethod
    def build_part_a(self):
        pass
    
    @abstractmethod
    def build_part_b(self):
        pass
    
    @abstractmethod
    def build_part_c(self):
        pass
    
    @abstractmethod
    def get_result(self) -> Product:
        pass

# 具体建造者
class ConcreteBuilder(Builder):
    def __init__(self):
        self.product = Product()
    
    def build_part_a(self):
        self.product.add("部件A")
    
    def build_part_b(self):
        self.product.add("部件B")
    
    def build_part_c(self):
        self.product.add("部件C")
    
    def get_result(self) -> Product:
        return self.product

# 指挥者
class Director:
    def __init__(self, builder: Builder):
        self.builder = builder
    
    def construct(self):
        self.builder.build_part_a()
        self.builder.build_part_b()
        self.builder.build_part_c()
        return self.builder.get_result()

# 使用示例
def main():
    builder = ConcreteBuilder()
    director = Director(builder)
    
    # 构建产品
    product = director.construct()
    print(product.show())

if __name__ == "__main__":
    main()


# 运行结果

# 产品包含: 部件A, 部件B, 部件C